import { userInfoApi, UserInfoType } from '@/api'
import { clearToken } from '@/utils'

import { RootThunkAction } from '.'

// 基础模板
export type UserType = {
  type: 'user/info'
  info:UserInfoType
}
function userInfoAction():RootThunkAction {
  return async (dispatch) => {
    //请求数据
    const res = await userInfoApi()
    
    //保存token到redux中
    dispatch({
      type:'user/info',
      info:res.data.data
    })
  }
}

function logoutAction():RootThunkAction {
  return async (dispatch) => {
    //清除数据数据
    clearToken()
    
    //保存token到redux中
    dispatch({
      type:'user/info',
      info:{} as UserInfoType
    })
  }
}

export { userInfoAction ,logoutAction}
